home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / utils / xad / developer / sources / tools / xadlist.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  5KB  |  204 lines

  1. #define NAME         "xadList"
  2. #define DISTRIBUTION "(Freeware) "
  3. #define REVISION     "0"
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        xadList
  8.     Author:        SDI
  9.     Distribution:    Freeware
  10.     Description:    shows the directory contents and archive type
  11.     Compileropts:    -
  12.     Linkeropts:    -gsi -l amiga
  13.  
  14.  1.0   18.11.98 : first version
  15. */
  16.  
  17. #include <proto/xadmaster.h>
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <exec/memory.h>
  21. #include <dos/dosasl.h>
  22. #include "SDI_defines.h"
  23. #define SDI_TO_ANSI
  24. #include "SDI_ASM_STD_protos.h"
  25.  
  26. #ifdef __SASC
  27.   #define dosbase     DOSBase 
  28.   #define xadmasterbase  xadMasterBase
  29.   #define ASSIGN_DOS
  30.   #define ASSIGN_XAD
  31. #else
  32.   struct DosLibrary *     DOSBase = 0;
  33.   struct xadMasterBase * xadMasterBase = 0;
  34.  
  35.   #define ASSIGN_DOS     DOSBase = dosbase;
  36.   #define ASSIGN_XAD     xadMasterBase = xadmasterbase;
  37. #endif
  38. struct ExecBase *     SysBase  = 0;
  39.  
  40. #define PARAM    "FILE/M,ALL/S,NE=NOEXTERN/S,ONLYKNOWN/S"
  41.  
  42. struct Args {
  43.   STRPTR *file;
  44.   ULONG   all;
  45.   ULONG   noextern;
  46.   ULONG      onlyknown;
  47. };
  48.  
  49. ULONG start(void)
  50. {
  51.   ULONG ret = RETURN_FAIL;
  52.   struct DosLibrary *dosbase;
  53.  
  54.   SysBase = (*((struct ExecBase **) 4));
  55.   { /* test for WB and reply startup-message */
  56.     struct Process *task;
  57.     if(!(task = (struct Process *) FindTask(0))->pr_CLI)
  58.     {
  59.       WaitPort(&task->pr_MsgPort);
  60.       Forbid();
  61.       ReplyMsg(GetMsg(&task->pr_MsgPort));
  62.       return RETURN_FAIL;
  63.     }
  64.   }
  65.  
  66.   if((dosbase = (struct DosLibrary *) OpenLibrary("dos.library", 37)))
  67.   {
  68.     struct xadMasterBase *xadmasterbase;
  69.     ASSIGN_DOS
  70.     if((xadmasterbase = (struct xadMasterBase *)
  71.     OpenLibrary("xadmaster.library", 1)))
  72.     {
  73.       struct Args args;
  74.       struct RDArgs *rda;
  75.       STRPTR a[2];
  76.       
  77.       a[0] = "";
  78.       a[1] = 0;
  79.       args.file = a;
  80.       args.all = args.noextern = args.onlyknown = 0;
  81.       
  82.       ASSIGN_XAD
  83.       if((rda = ReadArgs(PARAM, (LONG *) &args, 0)))
  84.       {
  85.         struct AnchorPath *ap;
  86.  
  87.         if(!args.file)        /* a bug in ReadArgs */
  88.           args.file = a;
  89.  
  90.         if((ap = (struct AnchorPath *)
  91.         AllocVec(sizeof(struct AnchorPath) + 300, MEMF_PUBLIC|MEMF_CLEAR)))
  92.         {
  93.           APTR buf;
  94.           ULONG size, first;
  95.  
  96.           ap->ap_BreakBits = SIGBREAKF_CTRL_C;
  97.           ap->ap_Strlen = 300;
  98.           size = xadMasterBase->xmb_RecogSize;
  99.  
  100.       if((buf = AllocVec(size, MEMF_ANY|MEMF_PUBLIC)))
  101.       {
  102.             ret = RETURN_OK;
  103.         while(ret <= RETURN_WARN && *args.file)
  104.         {
  105.           LONG retval, deep = 0;
  106.           UBYTE txt[130];
  107.           BPTR lock;
  108.  
  109.           first = 0;
  110.           if((lock = Lock(*args.file, SHARED_LOCK)))
  111.           {
  112.             if(Examine(lock, &ap->ap_Info))
  113.               if(ap->ap_Info.fib_DirEntryType >0)
  114.                 first = 1;
  115.             UnLock(lock);
  116.           }      
  117.  
  118.               for(retval = MatchFirst(*args.file, ap); !retval;
  119.               retval = MatchNext(ap))
  120.               {
  121.         sprintf(txt, "          ");
  122.         sprintf(txt+(deep%10), "%-108s", ap->ap_Info.fib_FileName);
  123.                 if(ap->ap_Flags & APF_DIDDIR)
  124.                 {
  125.                   ap->ap_Flags &= ~APF_DIDDIR; --deep;
  126.                 }
  127.                 else if(ap->ap_Info.fib_DirEntryType > 0)
  128.                 {
  129.                   if(!first)
  130.                   {
  131.                     Printf("%.53s <DIR>\n", txt);
  132.             if(args.all)
  133.                       ++deep;
  134.                   }
  135.                   if(args.all || first)
  136.                     ap->ap_Flags |= APF_DODIR;
  137.                 }
  138.                 else
  139.                 {
  140.           STRPTR res = "could not check";
  141.           ULONG s;
  142.           BPTR fh;
  143.         
  144.           if((s = ap->ap_Info.fib_Size) > size)
  145.             s = size;
  146.           
  147.           if((fh = Open(ap->ap_Buf, MODE_OLDFILE)))
  148.           {
  149.             if(Read(fh, buf, s) == s)
  150.             {
  151.               struct xadClient *xc;
  152.  
  153.               if((xc = xadRecogFile(s, buf, XAD_NOEXTERN, 
  154.               args.noextern, TAG_DONE)))
  155.                 res = xc->xc_ArchiverName;
  156.               else
  157.                 res = 0;
  158.             }
  159.             else
  160.               ret = RETURN_WARN;
  161.             Close(fh);
  162.           }
  163.           else
  164.             ret = RETURN_WARN;
  165.  
  166.           if(!args.onlyknown || res)
  167.           {
  168.             if(!res)
  169.               res = "unknown";
  170.                     Printf("%.48s %10ld %s\n", txt,
  171.                     ap->ap_Info.fib_Size, res);
  172.                   }
  173.                 }
  174.                 first = 0;
  175.               }
  176.               MatchEnd(ap);
  177.  
  178.               if(retval != ERROR_NO_MORE_ENTRIES)
  179.                 ret = RETURN_ERROR;
  180.           if(*(++args.file) && ret <= RETURN_WARN)
  181.             Printf("\n");
  182.         } /* while */
  183.         FreeVec(buf);
  184.       } /* AllocVec */
  185.           FreeVec(ap);
  186.     } /* AllocVec */
  187.         FreeArgs(rda);
  188.       } /* ReadArgs */
  189.  
  190.       if(CTRL_C)
  191.         SetIoErr(ERROR_BREAK);
  192.  
  193.       if(ret)
  194.         PrintFault(IoErr(), 0);
  195.  
  196.       CloseLibrary((struct Library *) xadmasterbase);
  197.     } /* OpenLibrary xadmaster */
  198.     else
  199.       Printf("Could not open xadmaster.library\n");
  200.     CloseLibrary((struct Library *) dosbase);
  201.   } /* OpenLibrary dos */
  202.   return ret;
  203. }
  204.